package com.zzyl.serve.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.serve.domain.Reservation;
import com.zzyl.serve.dto.ReservationDto;
import com.zzyl.serve.service.IReservationService;
import com.zzyl.serve.vo.TimeCountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{

    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public R<List<TimeCountVo>>countReservationsForEachTimeWithinTimeRange(Long time){
        List<TimeCountVo> count = reservationService.countReservationsForTim(time);
        return R.ok(count);
    }



    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
        int count =reservationService.getCancelledCoun(userId) ;
        return R.ok(count);
    }


    /**
     * 新增预约信息
     */
    @Autowired
    private IReservationService reservationService;
    @PostMapping
    @ApiOperation("新增预约信息")
    public AjaxResult add( @RequestBody Reservation reservation1)
    {
        return toAjax(reservationService.insertReservation(reservation1));
    }

    /**
     * 分页查询预约
     */
    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "pageNaum", value = "页码", required = true, dataType = "int", paramType = "query"),
                    @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
                    @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "int", paramType = "query")
            })
   public R<TableDataInfo>findReservationPage(
           @RequestParam(defaultValue = "1") int pageNum,
           @RequestParam(defaultValue = "10")int pageSize,
           @RequestParam(required = false)Integer status){
        TableDataInfo tableDataInfo = reservationService.ReservationPage(pageNum, pageSize, status);
        return R.ok(tableDataInfo);
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public R<Integer> cancelReservation(@PathVariable Long id) {
        return R.ok( reservationService.cancelReservation(id));
    }
}